<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return['basic']=$this->plugin_setting('basic');
$return['ischecklogin']=cfc('core')->checklogin('','',true);
$this->model('member')->upmember();
if($_RQ['op']=='get'){
	$return['basic']['bi_rate']=$return['basic']['bi_rate']?:1;
	$redfeeset=$return['basic']['redfeeset'];
	if(!$redfeeset){
		$redfeeset[]=array(
			'fee'=>3,
			'yfee'=>0,
			'addnum'=>10,
			'binum'=>$return['basic']['bi_rate']*3, //  3元/币
		);
		$redfeeset[]=array(
			'fee'=>36,
			'yfee'=>0,
			'addnum'=>365,
			'binum'=>$return['basic']['bi_rate']*36,
		);
		$redfeeset[]=array(
			'fee'=>99,
			'yfee'=>0,
			'addnum'=>1000,
			'binum'=>$return['basic']['bi_rate']*99,
		);
	}else{
		foreach($redfeeset as &$rv){
			$rv['binum']=intval($return['basic']['bi_rate']*$rv['fee']*100)/100;
		}
	}
	$return['item']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','credit1','credit2','credit3','mobile','groupid','avatar','nickname'));
	$return['item']['money']=$redfeeset[0]['fee'];
	$return['item']['key']=0;
	$return['redfeeset']=$redfeeset;
	$return['setgoumai']=$this->plugin_setting('goumai');
	exi($return);
}
if($_RQ['op']=='recharge'){
	$post=get_postdata();
	if(!$post['agree']){
		//exi('请先阅读协议！','error');
	}
	if(intval($post['money'])<=0){
		exi('请先设置充值金额！并且为整数！','error');
	}
	$redfeeset=$return['basic']['redfeeset'];
	if(!$redfeeset){
		$redfeeset[]=array(
			'fee'=>3,
			'yfee'=>0,
			'addnum'=>10,
			'binum'=>$return['basic']['bi_rate']*3, //  3元/币
		);
		$redfeeset[]=array(
			'fee'=>36,
			'yfee'=>0,
			'addnum'=>365,
			'binum'=>$return['basic']['bi_rate']*36,
		);
		$redfeeset[]=array(
			'fee'=>99,
			'yfee'=>0,
			'addnum'=>1000,
			'binum'=>$return['basic']['bi_rate']*99,
		);
	}else{
		foreach($redfeeset as &$rv){
			$rv['binum']=intval($return['basic']['bi_rate']*$rv['fee']*100)/100;
		}
	}
	$key=$post['key'];
	$select=$redfeeset[$key];
	$fee=sprintf("%.2f", intval($select['fee']));
	$data=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'fee'=>$fee,
		'credit'=>$select['binum']+$select['addnum'],
		'type'=>3,
		'wxapp_id'=>$_SESSION['appgid'],
		'createtime'=>TIMESTAMP
	);
	pdo_insert('core_recharge',$data);
	$id=pdo_insertid();
	$params=array(
		'action'=>'recharge',
		'id'=>$id,
		'fee'=>$fee,
		'title'=>'升级专享版套餐会员充值',
		'plugin'=>'core',
		//'pay_type'=>'wechat',
		'no_type'=>array('hdfk'),
		'back_url'=>'core/member.xunibi/pay_result',
		'success_url'=>'core/member.xunibi//type=3',
		'error_url'=>'core/member.xunibi//type=3',
	);
	if($_SESSION['container']=='aliapp' && $_SESSION['aliappopenid']){
		$params['pay_type']='alipay';
	}
	$pay_id=cfc('pay')->create_pay_order($params);
	pdo_update('core_recharge',array('pay_id'=>$pay_id),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	exi($pay_id);
}